package com.kuaiditu.assistant.api;

import android.content.Context;

import com.kuaiditu.assistant.api.assistant_api.AssistantApi;
import com.kuaiditu.assistant.api.kdy_api.STApi;
import com.kuaiditu.assistant.api.xz_api.XingZheApi;
import com.kuaiditu.assistant.api.yd_api.YDApi;
import com.kuaiditu.assistant.api.zzt_api.ZZTApi;
import com.kuaiditu.assistant.module.storage.AssistantUserStorage;

import okhttp3.OkHttpClient;

/**
 * Created by Eenie on 2017/8/31.
 * Email: eeniework@gmail.com
 * Des:
 */

public class ApiManager {
    private Context mContext;
    private AssistantApi sAssistantApi;
    private FileManager mFileManager;


    private OkHttpClient mOkHttpClient;
    private AssistantUserStorage mAssistantUserStorage;
    private ParamsAnalog mParamsAnalog;


    private YDApi mYDApi;
    private XingZheApi mXingZheApi;
    private STApi mSTApi;
    private ZZTApi mZZTApi;

    public ApiManager(Context context, OkHttpClient client, AssistantUserStorage assistantUserStorage, ParamsAnalog paramsAnalog) {
        this.mContext = context;
        mOkHttpClient = client;
        mParamsAnalog = paramsAnalog;
        this.mAssistantUserStorage = assistantUserStorage;
    }


    public AssistantApi getAssistantApi() {
        if (sAssistantApi == null) {
            synchronized (ApiManager.class) {
                if (sAssistantApi == null) {
                    sAssistantApi = new AssistantApi(mOkHttpClient, mAssistantUserStorage, this);
                }
            }
        }
        return sAssistantApi;
    }

    public YDApi getYDApi() {
        if (mYDApi == null) {
            synchronized (ApiManager.class) {
                if (mYDApi == null) {
                    mYDApi = new YDApi(mOkHttpClient, mParamsAnalog);
                }
            }
        }
        return mYDApi;
    }
    public XingZheApi getXingZheApi() {
        if (mXingZheApi == null) {
            synchronized (ApiManager.class) {
                if (mXingZheApi == null) {
                    mXingZheApi = new XingZheApi(mOkHttpClient, mParamsAnalog);
                }
            }
        }
        return mXingZheApi;
    }
    public STApi getSTApi() {
        if (mSTApi == null) {
            synchronized (ApiManager.class) {
                if (mSTApi == null) {
                    mSTApi = new STApi(mContext,mOkHttpClient, mParamsAnalog);
                }
            }
        }
        return mSTApi;
    }

    public FileManager getFileManager() {
        if (mFileManager == null) {
            synchronized (ApiManager.class) {
                if (mFileManager == null) {
                    mFileManager = new FileManager(mOkHttpClient);
                }
            }
        }
        return mFileManager;
    }
    public ZZTApi getZZTApi() {
        if (mZZTApi == null) {
            synchronized (ApiManager.class) {
                if (mZZTApi == null) {
                    mZZTApi = new ZZTApi(mParamsAnalog);
                }
            }
        }
        return mZZTApi;
    }


}
